using Axelerate.Silverlight3D.Media.Media3D;
using System;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Media;

namespace EasySL.Controls
{
    public class Tag3D
    {
        public Tag3D(double x, double y, double z, string text, string hyperlink, ControlTemplate template)
        {
            this.Tag = text;
            this.CenterPoint = new Point3D(x, y, z);
            HyperlinkButton button = new HyperlinkButton();
            TextBlock block = new TextBlock();
            block.Text = this.Tag;

            button.Content = block;
            if (!string.IsNullOrEmpty(hyperlink))
                button.NavigateUri = new Uri(hyperlink);
            button.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 0, 0x39, 0x4a));
            button.Template = template;
            this.LinkButton = button;
            this.LinkButton.Click += new RoutedEventHandler(TrackTagClick);
        }

        public void Redraw(double xOffset, double yOffset)
        {
            double num = this.CenterPoint.Z + 200.0;
            this.LinkButton.FontSize = 5 * (num / 100.0);
            double num2 = this.CenterPoint.Z + 200.0;
            if (num2 > 255.0)
            {
                num2 = 255.0;
            }
            if (num2 < 0.0)
            {
                num2 = 0.0;
            }
            this.LinkButton.Opacity = num2 / 255.0;
            Canvas.SetLeft(this.LinkButton, (this.CenterPoint.X+ xOffset) - (this.LinkButton.ActualWidth / 2.0));
            Canvas.SetTop(this.LinkButton, (-this.CenterPoint.Y + yOffset) - (this.LinkButton.ActualHeight / 2.0));
            Canvas.SetZIndex(this.LinkButton, Convert.ToInt32(this.CenterPoint.Z));
        }

        private void TrackTagClick(object sender, RoutedEventArgs e)
        {
            try
            {
                HtmlPage.Window.Invoke("trackEvent", new object[] { "TagCloud.Click", this.Tag, string.Format("{0} was clicked", this.Tag) });
            }
            catch (Exception)
            {
            }
        }

        public Point3D CenterPoint { get; set; }

        public HyperlinkButton LinkButton { get; set; }

        public string Tag { get; set; }
    }
}

